home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / ispell40.lha / ispell-4.0 / exp.c < prev    next >
C/C++ Source or Header  |  1993-05-31  |  5KB  |  239 lines

  1. /* Copyright (C) 1990, 1993 Free Software Foundation, Inc.
  2.  
  3.    This file is part of GNU ISPELL.
  4.  
  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 2, or (at your option)
  8.    any later version.
  9.  
  10.    This program is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.    GNU General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public License
  16.    along with this program; if not, write to the Free Software
  17.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include <stdio.h>
  20. #include <ctype.h>
  21. #include "ispell.h"
  22. #include "hash.h"
  23. #include "good.h"
  24. char words[50][MAX_WORD_LEN];
  25.  
  26. int
  27. expand (w)
  28.   char *w;
  29. {
  30.   char *p;
  31.   int i;
  32.   int len;
  33.   int c;
  34.  
  35.   i = 0;
  36.  
  37.   p = strchr (w, '/');
  38.  
  39.   if (p)
  40.     *p = 0;
  41.  
  42.   downcase (words[i++], w);
  43.  
  44.   if (p == NULL)
  45.     {
  46.       words[i][0] = 0;
  47.       return (i);
  48.     }
  49.  
  50.   len = strlen (w);
  51.  
  52.   p++;
  53.   while (1)
  54.     {
  55.       (void) strcpy (words[i], words[0]);
  56.  
  57.       c = *p;
  58.       if (isupper (c))
  59.     c = tolower (c);
  60.  
  61.       switch (*p)
  62.     {
  63.     case 'v':
  64.       if (w[len - 1] == 'e')
  65.         (void) strcpy (words[i] + len - 1, "ive");
  66.       else
  67.         (void) strcpy (words[i] + len, "ive");
  68.       break;
  69.     case 'n':
  70.       if (w[len - 1] == 'e')
  71.         (void) strcpy (words[i] + len - 1, "ion");
  72.       else if (w[len - 1] == 'y')
  73.         (void) strcpy (words[i] + len - 1, "ication");
  74.       else
  75.         (void) strcpy (words[i] + len, "en");
  76.       break;
  77.     case 'x':
  78.       if (w[len - 1] == 'e')
  79.         (void) strcpy (words[i] + len - 1, "ions");
  80.       else if (w[len - 1] == 'y')
  81.         (void) strcpy (words[i] + len - 1, "ications");
  82.       else
  83.         (void) strcpy (words[i] + len, "ens");
  84.       break;
  85.     case 'h':
  86.       if (w[len - 1] == 'y')
  87.         (void) strcpy (words[i] + len - 1, "ieth");
  88.       else
  89.         (void) strcpy (words[i] + len, "th");
  90.       break;
  91.     case 'y':
  92.       (void) strcpy (words[i] + len, "ly");
  93.       break;
  94.     case 'm':
  95.       (void) strcpy (words[i] + len, "'s");
  96.       break;
  97.     case 'g':
  98.       if (w[len - 1] == 'e')
  99.         (void) strcpy (words[i] + len - 1, "ing");
  100.       else
  101.         (void) strcpy (words[i] + len, "ing");
  102.       break;
  103.     case 'j':
  104.       if (w[len - 1] == 'e')
  105.         (void) strcpy (words[i] + len - 1, "ings");
  106.       else
  107.         (void) strcpy (words[i] + len, "ings");
  108.       break;
  109.     case 'd':
  110.       if (w[len - 1] == 'e')
  111.         {
  112.           (void) strcpy (words[i] + len - 1, "ed");
  113.         }
  114.       else if (w[len - 1] == 'y')
  115.         {
  116.           if (isvowel (w[len - 2]))
  117.         (void) strcpy (words[i] + len, "ed");
  118.           else
  119.         (void) strcpy (words[i] + len - 1, "ied");
  120.         }
  121.       else
  122.         {
  123.           (void) strcpy (words[i] + len, "ed");
  124.         }
  125.       break;
  126.     case 't':
  127.       if (w[len - 1] == 'e')
  128.         {
  129.           (void) strcpy (words[i] + len - 1, "est");
  130.         }
  131.       else if (w[len - 1] == 'y')
  132.         {
  133.           if (isvowel (w[len - 2]))
  134.         (void) strcpy (words[i] + len, "est");
  135.           else
  136.         (void) strcpy (words[i] + len - 1, "iest");
  137.         }
  138.       else
  139.         {
  140.           (void) strcpy (words[i] + len, "est");
  141.         }
  142.       break;
  143.     case 'r':
  144.       if (w[len - 1] == 'e')
  145.         {
  146.           (void) strcpy (words[i] + len - 1, "er");
  147.         }
  148.       else if (w[len - 1] == 'y')
  149.         {
  150.           if (isvowel (w[len - 2]))
  151.         (void) strcpy (words[i] + len, "er");
  152.           else
  153.         (void) strcpy (words[i] + len - 1, "ier");
  154.         }
  155.       else
  156.         {
  157.           (void) strcpy (words[i] + len, "er");
  158.         }
  159.       break;
  160.     case 'z':
  161.       if (w[len - 1] == 'e')
  162.         {
  163.           (void) strcpy (words[i] + len - 1, "ers");
  164.         }
  165.       else if (w[len - 1] == 'y')
  166.         {
  167.           if (isvowel (w[len - 2]))
  168.         (void) strcpy (words[i] + len, "ers");
  169.           else
  170.         (void) strcpy (words[i] + len - 1, "iers");
  171.         }
  172.       else
  173.         {
  174.           (void) strcpy (words[i] + len, "ers");
  175.         }
  176.       break;
  177.     case 's':
  178.       if (w[len - 1] == 'y')
  179.         {
  180.           if (isvowel (w[len - 2]))
  181.         (void) strcpy (words[i] + len, "s");
  182.           else
  183.         (void) strcpy (words[i] + len - 1, "ies");
  184.         }
  185.       else if (issxzh (w[len - 1]))
  186.         {
  187.           (void) strcpy (words[i] + len, "es");
  188.         }
  189.       else
  190.         {
  191.           (void) strcpy (words[i] + len, "s");
  192.         }
  193.       break;
  194.     case 'p':
  195.       if (w[len - 1] == 'y')
  196.         {
  197.           if (isvowel (w[len - 2]))
  198.         (void) strcpy (words[i] + len, "ness");
  199.           else
  200.         (void) strcpy (words[i] + len - 1, "iness");
  201.         }
  202.       else
  203.         {
  204.           (void) strcpy (words[i] + len, "ness");
  205.         }
  206.       break;
  207.     default:
  208.       (void) fprintf (stderr, "syntax error %s\n", w);
  209.       break;
  210.     }
  211.       if (strlen (words[i]) < 4)
  212.     {
  213.       (void) fprintf (stderr, "warning meaningless flag: ");
  214.       (void) fprintf (stderr, "%s/%c ", words[0], *p);
  215.       (void) fprintf (stderr, "produces less than 4 bytes\n");
  216.     }
  217.       else
  218.     {
  219.       i++;
  220.     }
  221.       p++;
  222.       if (*p == 0 || *p == '\n')
  223.     break;
  224.       if (*p != '/')
  225.     {
  226.       (void) fprintf (stderr, "syntax error %s\n", w);
  227.       break;
  228.     }
  229.       p++;
  230.       if (*p == 0)
  231.     {
  232.       (void) fprintf (stderr, "syntax error %s\n", w);
  233.       break;
  234.     }
  235.     }
  236.   words[i][0] = 0;
  237.   return (i);
  238. }
  239.